import { replaceSensitiveText } from './tools';

import {ChatItemType} from './constants'

export const getErrText = (err: any, def = '') => {
  const msg: string =
    typeof err === 'string'
      ? err
      : err?.response?.data?.message || err?.response?.message || err?.message || def;
  msg && console.log('error =>', msg);
  return replaceSensitiveText(msg);
};

export const getChatTitleFromChatMessage = (message?: ChatItemType, defaultValue = '新对话') => {
  // @ts-ignore
  const textMsg = message?.value.find((item) => item.type === ChatItemValueTypeEnum.text);

  if (textMsg?.text?.content) {
    return textMsg.text.content.slice(0, 20);
  }

  return defaultValue;
};